<?php

namespace App\Http\Controllers;

use App\Eloquent\Ad;
use App\Eloquent\User;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
use App\Eloquent\Navigation;
use App\Eloquent\FriendlyLink;
use DB;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function __construct(){
        $this->init();
        $navigation_menu=0;
        if(isset($_GET['navigation_id'])){
            $navigation_menu=$_GET['navigation_id'];
        }else{
            $navigation_menu=session()->get('navigation_menu');
        }
        session()->put('navigation_menu',$navigation_menu);

        $menu=0;
        if(isset($_GET['menu'])){
            $menu=$_GET['menu'];
        }else{
            $menu=session()->get('user_current_menu');
        }
        session()->put('user_current_menu',$menu);
        //获取页面共享广告位
        $share_ads=Ad::getShareAds('ads_share');
        $shares_ads=array();
        foreach($share_ads as $key =>$share_ad){
            $shares_ads[$share_ad->position]=$share_ad;
        }
//        /*
//         * 获取APP下载链接
//         */
//        $app_links=DB::table('codes')
//            ->where('type_id','app_link')
//            ->get();
//        $links=array();
//        foreach($app_links as  $app_link){
//            $links[$app_link->code]=$app_link->description;
//        }

        // 获取顶部导航
        $navigations=Navigation::getNavigation();
        // 获取底部友情链接

        $friendlink=FriendlyLink::getFriendlyLink('friend_link_two','8');

        view()->share('shares_ads',$shares_ads);
        view()->share('navigations',$navigations);
        view()->share('friendlinks',$friendlink);
        view()->share('navigation_menu',$navigation_menu);
        view()->share('menu',$menu);
        view()->share('user',User::user());
    }

    //所有子类建造构造方法，请重写这个方法
    public function init(){

    }
}
